<?php

namespace App\Http\Resources\Estate\CollectorMeterResource;

use App\Models\ElectricCommunity;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;

/**
 * 采集器资源
 * Class CollectorMeterCollection
 * @package App\Http\Resources\Estate\CollectorMeterResource
 */
class CollectorMeterCollection extends ResourceCollection
{
    protected $dates = ['create_time','update_time'];
    /**
     * Transform the resource collection into an array.
     *
     * @param Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [

            'data'         => $this->collection->map(function ($item) {

                return [
                    'id'         => $item->id,
                    'name'       => $item->name,
                    'code'        => $item->code,
                    'community'  => $item->one_community->name??"未绑定小区",
                    'agent'    => $item->one_agent->agent_name??"未绑定代理商",
                    'create_time' => $item->create_time,
                    'update_time' => $item->update_time,
                    'status'=>$item->status,
                ];
            }),
            'total'        => $this->total(), // 数据总数
            'per_page'     => $this->perPage(), // 每页数量
            'current_page' => $this->currentPage(), // 当前页码
        ];
    }
}
